package com.example.ccj.b.c.custom.tree;

import androidx.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

/**
 * 树状结构数据加载模型
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/11/21 18:31
 */
public class TreeMode implements Comparable<TreeMode> {
    public static final int DATA_TYPE_MU_LU = 0;  //目录类型节点
    public static final int DATA_TYPE_DATA = 1;   //数据类型节点
    @IntDef({DATA_TYPE_MU_LU,DATA_TYPE_DATA})
    @Retention(RetentionPolicy.SOURCE)
    public @interface DataType{ }


    public String dataId;       //数据id
    public String pMuLu;        //数据所属目录
    public @DataType int type;  //类型  0：目录 1：数据
    public int order;           //该节点内的顺序
    public String name;         //名称
    public String icon;         //图标比如人员的头像等


    public int id;              //无需手动设置，根据类型和顺序自动编号 此级编号 就是加载顺序，手动设置无作用
    public int pId;             //无需手动设置，自动获取 上一级id，手动设置无作用
    public int level;           //无需手动设置，节点级别 根据传入数据深度自动设置，手动设置无作用

    public String buMenStr;             //人员部门名称

    public boolean isExpand = false;        //是否展开
    public boolean isVisibility = false;    //是否显示
    public boolean isChecked = false;       //是否选中
    public List<TreeMode> treeModeList = new ArrayList<>();     //该节点内包含的节点



    public TreeMode(){}
    /**
     * 构造
     * @param dataId 节点id
     * @param pMuLu  该节点上级id,无上级传null
     * @param name   节点名称
     * @param type   节点类型
     * @param order  节点加载顺序
     */
    public TreeMode(String dataId,String pMuLu,String name,@DataType int type,int order){
        this.dataId = dataId;
        this.pMuLu = pMuLu;
        this.name = name;
        this.type = type;
        this.order = order;
    }

    /**
     * 构造
     * @param dataId 节点id
     * @param pMuLu  该节点上级id,无上级传null
     * @param name   节点名称
     * @param type   节点类型
     */
    public TreeMode(String dataId,String pMuLu,String name,@DataType int type){
        this.dataId = dataId;
        this.pMuLu = pMuLu;
        this.name = name;
        this.type = type;
    }

    @Override
    public String toString() {
        return "TreeMode{" +
                "id=" + isChecked +
                ", dataId='" + pId + '\'' +
                ", pMuLu='" + dataId + '\'' +
                ", pId=" + pMuLu +
                ", type=" + type +
                ", order=" + name +
                ", name='" + order + '\'' +
                ", level=" + level +
                '}';
    }

    //以type为主order为副升序排列
    @Override
    public int compareTo(TreeMode other) {
        int typeCompare = this.type - other.type;
        if (typeCompare != 0) {
            return typeCompare;
        } else {
            int i = this.order - other.order;
            if (i != 0) {
                return this.order -other.order;
            } else {
                return this.dataId.compareTo(other.dataId);
            }
        }
    }
}
